//
//  ViewController.m
//  FlutterHybrid
//
//  Created by yuan on 2019/11/4.
//  Copyright © 2019 yuan. All rights reserved.
//

#import "ViewController.h"
#import <flutter_boost/FlutterBoost.h>

@interface ViewController ()<FlutterBoostDelegate>
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"FlutterBoost示例";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *btn = createBtn(@"push页面，传参",@selector(pushVC),self);
    btn.frame = CGRectMake(0, 80, 200, 40);
    [self.view addSubview:btn];
    
    UIButton *btn1 = createBtn(@"present页面，传参",@selector(presentVC),self);
    btn1.frame = CGRectMake(0, CGRectGetMaxY(btn.frame) + 20, 200, 40);
    [self.view addSubview:btn1];
    
    UIButton *btn2 = createBtn(@"push页面，返回参数回参",@selector(pushWithPragma),self);
    btn2.frame = CGRectMake(0, CGRectGetMaxY(btn1.frame) + 20, 200, 40);
    [self.view addSubview:btn2];
    
    UIButton *btn4 = createBtn(@"NativeCallFlutter",@selector(nativeCall),self);
    btn4.frame = CGRectMake(0, CGRectGetMaxY(btn2.frame) + 20, 200, 40);
    [self.view addSubview:btn4];
    
    [self addEventListener];
}

- (void)addEventListener{
    [FlutterBoost.instance addEventListener:^(NSString *name, NSDictionary *arguments) {
        NSLog(@"%@:%@",name,arguments);
    } forName:@"flutter_to_native"];
}

#pragma mark - *********** Event ***********

- (void)pushVC {
    FlutterBoostRouteOptions *options = FlutterBoostRouteOptions.new;
    options.pageName = @"firstPage";
    options.arguments = @{@"key":@"参数",@"isAnimated":@(true)};
    [FlutterBoost.instance open:options];
}

- (void)presentVC{
    FlutterBoostRouteOptions *options = FlutterBoostRouteOptions.new;
    options.pageName = @"secondPage";
    options.arguments = @{@"key":@"参数",@"isAnimated":@(true),@"isPresent":@(true)};
    [FlutterBoost.instance open:options];
}

- (void)pushWithPragma{
    FlutterBoostRouteOptions *options = FlutterBoostRouteOptions.new;
    options.pageName = @"threePage";
    options.arguments = @{@"key":@"参数",@"isAnimated":@(true)};
    [FlutterBoost.instance open:options];
}

- (void)nativeCall{
    [FlutterBoost.instance sendEventToFlutterWith:@"native_call_flutter" arguments:@{@"key":@"native_call_123"}];
}

@end
